#!/usr/bin/env python
import unittest
import pdb
from django.test import TestCase, Client
from django.core.urlresolvers import reverse

class TestMyViews(TestCase):
    
    fixtures = ['pybb.json']
    
    def setUp(self):
        self.client = Client()
        
    def browsePage(self, view, **kwargs):
        url = reverse(view, **kwargs)
        response = self.client.get(url)
        self.failUnlessEqual(response.status_code, 200)
        
    def login(self):
        self.assertEqual(self.client.login(username = "admin", password = "120"), True)
    
    def testIndex(self):
        response = self.client.get(reverse("index"))
        self.failUnlessEqual(response.status_code, 200)
    
    def testBoard(self):
        self.browsePage('board', kwargs = {"board_slug":"python"})
        
    def testTopic(self):

        self.login()
        self.browsePage('add_topic', kwargs = {"board_slug":"python"})
        response = self.client.post(reverse('add_topic',kwargs = {"board_slug":"python"}),{\
            "title" : "this is a topic for test.",
            "body"  : "body!!!",
        })

        self.assertEqual(response.status_code, 200)
        response = self.client.get (reverse('topic', kwargs={"topic_id":1}))
        self.assertContains(response, "this is a topic for test.")

    
    def testAddTalk(self):
        
        self.login()
        add_talk_url = reverse('add_talk', kwargs = {"topic_id":1})

        #self.browsePage('add_talk', kwargs = {"topic_id":1})
        response = self.client.post(add_talk_url, {\
            "body":"reply"
        })
        
"""
class TestMemberViews(TestCase):
    
    def testMemberLogin(self):
        pass
        
    def testMemberRegister(self):
        pass
        
    def testMemberLogout(self):
        pass
    
    def testMemberProfileModify(self):
        pass
    
    def testMemberListAvatar(self):
        pass
        
    def testMemberUploadAvatar(self):
        pass
"""
    
    
    
    
    
    
    
        
